package com.heima.wemedia.controller.v1;

import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.DownUpDto;
import com.heima.model.wemedia.dtos.NewsAuthDTO;
import com.heima.model.wemedia.dtos.WmNewsDTO;
import com.heima.model.wemedia.dtos.WmNewsPageReqDTO;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @package com.heima.wemedia.controller.v1
 * @Date 2022/3/1
 * @project heima-leadnews
 */
@Api(value = "文章管理API", tags = "文章管理API")
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;
    @ApiOperation("分页查询")
    @PostMapping("list")
    public ResponseResult selectPage(@RequestBody WmNewsPageReqDTO dto) {
        return wmNewsService.selectPage(dto);
    }
    @ApiOperation("保存文章")
    @PostMapping("submit")
    public ResponseResult submitNews(@RequestBody WmNewsDTO dto){
        return wmNewsService.submitNews(dto);
    }
    @ApiOperation("根据id查询")
    @GetMapping("/one/{id}")
    public ResponseResult selectOne(@PathVariable("id") Integer id){
        return wmNewsService.selectOne(id);
    }


    @ApiOperation("deleteNews")
    @GetMapping("del_news/{id}")
    public ResponseResult deleteNews(@PathVariable("id") Integer id){
       return wmNewsService.deleteNews(id);
    }
    @ApiOperation("上下架")
    @PostMapping("down_or_up")
    public ResponseResult downorup(@RequestBody DownUpDto dto){
        return wmNewsService.downorup(dto);
    }

    @ApiOperation("查询自媒体文章信息")
    @PostMapping("/list_vo")
    public ResponseResult findList(@RequestBody NewsAuthDTO dto){
        return wmNewsService.findList(dto);
    }
    @ApiOperation("查询文章详情")
    @GetMapping("/one_vo/{id}")
    public ResponseResult findWmNewSOne(@PathVariable("id") Integer id){
        return wmNewsService.findWmNewSOne(id);
    }

    @ApiOperation("人工审核通过")
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDTO dto){
        return wmNewsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_PASS,dto);
    }

    @ApiOperation("人工审核驳回")
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDTO dto){
        return wmNewsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_FAIL,dto);
    }

    @PostMapping("/update")
    public ResponseResult updateWmnews(@RequestBody WmNews wmNews){
         wmNewsService.updateById(wmNews);
         return ResponseResult.okResult();
    }
}
